﻿Public Class ShellUtil
    Private Const WAIT_INFINITE As Long = -1&
    Private Const SYNCHRONIZE As Long = &H100000

    Private Declare Function OpenProcess Lib "kernel32" _
      (ByVal dwDesiredAccess As Long, _
       ByVal bInheritHandle As Boolean, _
       ByVal dwProcessId As Long) As Long

    Private Declare Function WaitForSingleObject Lib "kernel32" _
      (ByVal hHandle As Long, _
       ByVal dwMilliseconds As Long) As Long

    Private Declare Function CloseHandle Lib "kernel32" _
      (ByVal hObject As Long) As Long

    'NO FUNCIONA
    'http://vbnet.mvps.org/index.html?code/faq/waitforsingleobject2.htm
    Public Shared Function shellEsperando(ByVal cmdline As String) As Boolean
        Dim hProcess As Long
        Dim taskId As Long
        taskId = Shell(cmdline, vbNormalFocus)
        hProcess = OpenProcess(SYNCHRONIZE, True, taskId)
        Call WaitForSingleObject(hProcess, WAIT_INFINITE)
        CloseHandle(hProcess)
    End Function
End Class
